//
//  JJMainTabBarControllerViewController.swift
//  JJSina
//
//  Created by mac on 2017/11/30.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit

class JJMainTabBarControllerViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 添加自定义标签栏
        let tabbar = JJTabBar()
        setValue(tabbar, forKey: "tabBar")
        tabbar.colouse = {
            print("anniu 待机点击")
        }
        // 设置代理
        tabbar.JJdelegate = self
        tabbar.QWDelegate = self
        // 首页
        addChildViewController(JJHomeViewController(), title: "首页", imageName: "tabbar_home")
        
        // 消息
        addChildViewController(JJMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        
        // 发现
        addChildViewController(JJDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        
        // 我的
        addChildViewController(JJProfileViewController(), title: "我的", imageName: "tabbar_profile")
        
        // Do any additional setup after loading the view.
    }

    
    func addChildViewController(_ childController: UIViewController, title: String, imageName: String) {
        // 设置控制名称
        childController.title = title
        
        // 设置标题颜色
    childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: JJ_THEMECOLOR], for: UIControlState.selected)
        
        // 设置背景图片
        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        // 添加子控制器
    addChildViewController(JJMainNavigationController(rootViewController: childController))
           
    }
}

// 遵守协议
extension JJMainTabBarControllerViewController: JJTabBarDelegate ,QWDelegate {
    func composeButtonDidSelected() {
    
    }
    func cbtn() {
        print("sifjlskjf")
    }
}
